package com.jingming.consult.fragment

import android.os.Bundle
import com.jingming.consult.R
import com.jingming.consult.base.BaseFragment
import com.jingming.consult.bean.JokeBean
import com.jingming.consult.network.MobileApi
import com.jingming.consult.network.utils.NetGenericityObserver
import com.jingming.consult.videoplayer.LogUtil
import io.reactivex.disposables.Disposable
import kotlinx.android.synthetic.main.fragmentthree.*
import java.lang.StringBuilder
import java.util.ArrayList

class ThreeFragment : BaseFragment() {
    override fun getLayoutid(): Int {
        return R.layout.fragmentthree
    }

    override fun onCreateView(savedInstanceState: Bundle?) {
        super.onCreateView(savedInstanceState)
        initView()
        initData()
    }

    private fun initView() {

        tvResult.setOnClickListener {
            initData()
        }
    }

    fun initData() {
        MobileApi.getInstance().getJoke(0, 5, "type")
            .subscribe(object : NetGenericityObserver<ArrayList<JokeBean>>(activity!!) {
                override fun onSubscribed(disposable: Disposable?) {
                }

                override fun onSuccess(t: ArrayList<JokeBean>?, errorMsg: String?) {
                    val toString = StringBuilder()

                    for (index in t!!) {
                        toString.append(index.text+"\n")
                    }

                    tvResult.text = toString
                }

                override fun onFail(msg: String) {
                    tvResult.text = msg
                }

            })

    }
}